<template>
  <div class="order">
    <h4>订单管理</h4>
    <div class="search">
      <p>
        <input type="text" placeholder="关键字" v-model="search" /><button
          @click="btnsuo"
        >
          搜索
        </button>
      </p>

      <el-select v-model="value" placeholder="请选择" @change="changeorder">
        <el-option label="二手房出租" value="二手房出租"> </el-option>
        <el-option label="有房出租" value="有房出租"> </el-option>
      </el-select>
    </div>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column fixed type="index" label="序号" width="200">
      </el-table-column>

      <el-table-column prop="number" label="编号" width="200">
      </el-table-column>

      <el-table-column prop="name" label="用户名" width="300">
      </el-table-column>

      <el-table-column prop="phone" label="手机号" width="200">
      </el-table-column>

      <el-table-column prop="type" label="类型" width="200"> </el-table-column>

      <el-table-column prop="price" label="支付金额" width="200">
      </el-table-column>

      <el-table-column prop="payTime" label="支付时间" width="200">
      </el-table-column>

      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="text" size="small">编辑</el-button>
          <el-button type="text" size="small" @click="btndel(scope)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      search: "",
      total: null,
      tableData: [],
      pageIndex: 1,
      pageSize: 5,
      currentPage4: 1,
      value: "",
    };
  },

  methods: {
    //分页
    Order(pageIndex, pageSize) {
      this.$http
        .get("/api/getOrder", {
          params: {
            pageIndex: pageIndex,
            pageSize: pageSize,
          },
        })
        .then((res) => {
          console.log(res);
          this.tableData = res.data.data;
          this.total = res.data.total;
        });
    },

    handleCurrentChange(val) {
      this.pageIndex = val;
      this.Order(this.pageIndex, this.pageSize);
    },

    handleSizeChange(val) {
      this.pageSize = val;
      this.Order(this.pageIndex, this.pageSize);
    },
    //搜索
    btnsuo() {
      this.$http
        .post("/api/searchInp", {
          value: this.search,
        })
        .then((res) => {
          console.log(res);
          if (res.data.code === 1) {
            this.tableData = res.data.data;
            this.$message.success("搜索成功");
          }
        });
    },

    //删除
    btndel(scope) {
      console.log(scope.row.id);
      this.$http.post("/api/orderDelete", { id: scope.row.id }).then((res) => {
        console.log(res);
        if (res.data.code === 1) {
          this.$message.success("删除成功");
          this.Order(this.pageIndex, this.pageSize);
        }
      });
    },

    //状态筛选
    changeorder() {
      console.log(this.value);
      this.$http
        .post("/api/OrderSelect", {
          value: this.value,
        })
        .then((res) => {
          if (res.data.code === 1) {
            this.$message.success(res.data.message);
            this.tableData = res.data.data;
          }
        });
    },
  },

  created() {
    this.Order(this.pageIndex, this.pageSize);
  },
};
</script>

<style>
h4{
  width: 100%;
  height: 50px;
  line-height: 50px;
}
.order{
  background: #e6e6e6;
}
.cell {
  text-align: center;
}
.search{
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
}
.search p input {
  padding: 10px 0;
  border-radius: 5px;
  border: 1px solid #e6e6e6;
}
.search p button {
  margin: 0 5px;
  padding: 9px 15px;
  background: skyblue;
  border: none;
  color: #fff;
}
</style>